* Do-file "Redistribution in a political union": Figure 1 and Table 1 
* use "EURedistribution.dta"

sort id year
xtset id year 


* generate fixed effects: country (ctr) and year (yr)
tab id, gen(ctr)
tab year, gen(yr)

* generate trend
tab year
gen trend = year-1979
tab trend

* Government ideology (Seki & Williamson 2014, see main text for full reference)
tab cpg_sw2014
recode cpg_sw2014 (0/2=1) (.=.) (else=0), gen(right)
recode cpg_sw2014 (2.01/3.99=1) (.=.) (else=0), gen(center)
recode cpg_sw2014 (4/max=1) (.=.) (else=0), gen(left)



************
*** Figure 1
************

*** Ireland
twoway (scatter OBB_GNI GNIpercapitaPPSEU15100 if country=="Ireland", mlabel(year) msize(vsmall)) (lfit OBB_GNI GNIpercapitaPPSEU15100 if country=="Ireland", lcolor(black)), graphregion(fcolor(white)) /*
*/  plotregion(fcolor(white)) yscale(range(-1.0 6)) ylabel(-1(1)6) title(Ireland, tstyle(size(medsmall))) xtitle(GNI per capita (% of EU average), tstyle(size(medsmall))) /*
*/ ytitle(OBB (% of GNI), tstyle(size(medsmall))) yline(0, lcolor(black) lpattern(dash)) legend(off) saving(Ireland, replace)

*** Greece
twoway (scatter OBB_GNI GNIpercapitaPPSEU15100 if country=="Greece", mlabel(year) msize(vsmall)) (lfit OBB_GNI GNIpercapitaPPSEU15100 if country=="Greece", lcolor(black)), graphregion(fcolor(white)) /* 
*/plotregion(fcolor(white)) yscale(range(-1.0 6)) ylabel(-1(1)6) title(Greece, tstyle(size(medsmall))) xtitle(GNI per capita (% of EU average), tstyle(size(medsmall))) /*
*/ ytitle(OBB (% of GNI), tstyle(size(medsmall))) yline(0, lcolor(black) lpattern(dash)) legend(off) saving(Greece, replace) 

*** Hungary
twoway (scatter OBB_GNI GNIpercapitaPPSEU15100 if country=="Hungary", mlabel(year) msize(vsmall)) (lfit OBB_GNI GNIpercapitaPPSEU15100 if country=="Hungary", lcolor(black)), graphregion(fcolor(white)) /*
*/ plotregion(fcolor(white)) yscale(range(-1.0 6)) ylabel(-1(1)6) title(Hungary, tstyle(size(medsmall))) xtitle(GNI per capita (% of EU average), tstyle(size(medsmall))) /*
*/ ytitle(OBB (% of GNI), tstyle(size(medsmall))) yline(0, lcolor(black) lpattern(dash)) legend(off) saving(Hungary, replace)

*** Germany
twoway (scatter OBB_GNI GNIpercapitaPPSEU15100 if country=="Germany", mlabel(year) msize(vsmall)) (lfit OBB_GNI GNIpercapitaPPSEU15100 if country=="Germany", lcolor(black)), graphregion(fcolor(white)) /* 
*/ plotregion(fcolor(white)) yscale(range(-1.0 6)) ylabel(-1(1)6) title(Germany, tstyle(size(medsmall))) xtitle(GNI per capita (% of EU average), tstyle(size(medsmall))) /*
*/ ytitle(OBB (% of GNI), tstyle(size(medsmall))) yline(0, lcolor(black) lpattern(dash)) legend(off) saving(Germany, replace)


* Figure 1 (combined plot)
graph combine Ireland.gph Greece.gph Hungary.gph Germany.gph, title("Figure 1. Relative income and EU redistribution", tstyle(size(medium))) graphregion(fcolor(white)) plotregion(fcolor(white)) /*
*/ note("Note. Relative income is GNI per capita as percent of EU average." "EU redistribution is Operating Budgetary Balance (OBB) as percent of GNI." /*
*/ "Positive (negative) values of OBB mean that countries are net beneficiaries (contributors) of EU redistribution" "For details of the data, see 'Data' section below.", size(small))
graph drop _all


***********************************************************************
************** TABLE 1 ************************************************
***********************************************************************

***** Fixed effects (xtpcse)
***** DV: OBB % of GNI 
sort id year
xtset id year 

* #1
xtpcse OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net ctr* yr* 
outreg2 using table1, tstat word bdec(2) tdec(2) replace

testparm ctr*
testparm yr* 

		* R2, within
		xtreg OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net yr*, fe


* #2: Add EU-level political variables (note: govt_per108=government EU position)
xtpcse OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.ssi l.govt_per108 ctr* yr*   
outreg2 using table1, tstat word bdec(2) tdec(2) append

testparm ctr*
testparm yr* 
		
		* R2, within
		xtreg OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.ssi l.govt_per108 yr*, fe  
		
		
* #3: Add domestic political variables
xtpcse OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.center l.right ctr* yr*   
outreg2 using table1, tstat word bdec(2) tdec(2) append

testparm ctr*
testparm yr* 

		* R2, within
		xtreg OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.center l.right yr*, fe   


* #4: All variables together
xtpcse OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.ssi l.govt_per108 l.center l.right ctr* yr*   
outreg2 using table1, tstat word bdec(2) tdec(2) append

testparm ctr*
testparm yr* 

		* R2, within
		xtreg OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.ssi l.govt_per108 l.center l.right yr*, fe   


*** Models including country-specific time trend
* #5
xtpcse OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net c.trend##i.ctr* yr* 
outreg2 using table1, tstat word bdec(2) tdec(2) append

xtpcse OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net trend ctr* c.trend#i.ctr*  yr* 
testparm ctr*
testparm yr* 
testparm c.trend#i.ctr*

			* R2, within
		xtreg OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net c.trend##i.ctr* yr*, fe


* #6: Add EU-level political variables
xtpcse OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.ssi l.govt_per108 c.trend##i.ctr* yr*   
outreg2 using table1, tstat word bdec(2) tdec(2) append

xtpcse OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.ssi l.govt_per108 trend ctr* c.trend#i.ctr* yr*   
testparm ctr*
testparm yr* 
testparm c.trend#i.ctr*
		
			
		* R2, within
		xtreg OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.ssi l.govt_per108 c.trend##i.ctr* yr*, fe


* #7: Add domestic political variables
xtpcse OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.center l.right c.trend##i.ctr* yr*   
outreg2 using table1, tstat word bdec(2) tdec(2) append

xtpcse OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.center l.right trend ctr* c.trend#i.ctr* yr*   
testparm ctr*
testparm yr* 
testparm c.trend#i.ctr*

		* R2, within
		xtreg OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.center l.right c.trend##i.ctr* yr*, fe   


* #8: All variables together
xtpcse OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.ssi l.govt_per108 l.center l.right c.trend##i.ctr* yr*   
outreg2 using table1, tstat word bdec(2) tdec(2) append

xtpcse OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.ssi l.govt_per108 l.center l.right ctr* c.trend#i.ctr* yr*   
testparm ctr*
testparm yr* 
testparm c.trend#i.ctr*

		* R2, within
		xtreg OBB_GNI l.GNIpercapitaPPSEU15100 l.NationalUnemplymnetrate l.gini_net l.ssi l.govt_per108 l.center l.right c.trend##i.ctr* yr*, fe   


*** End do-file for Figure 1 and Table 1

